home *** CD-ROM | disk | FTP | other *** search
- /************
-
- Sample program for using the CIconButton CDEF 1.0
- by Ramon M. Felciano
- felciano@camis.stanford.edu
-
- ©1993 Ramon M. Felciano, All Rights Reserved
-
- ********/
- #include "CIconButton.CLib.h"
-
- #define kCIconButtonCDEFID 20
- #define kButtonProc (16 * kCIconButtonCDEFID)
-
- #define kSampleMain 650
- #define kSampleShell 3210
- #define kSampleAlt 700
-
- #define atLeft 0x08
- #define atRight 0x0C
- #define atTop 0x02
- #define atBottom 0x03
-
-
-
- /****
- *
- * InitMacintosh()
- *
- ****/
-
- void InitMacintosh(void)
-
- {
- MaxApplZone();
-
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- }
- /* end InitMacintosh */
-
-
-
- unsigned short RangedRdm( unsigned short min, unsigned short max )
- /* assume that min is less than max */
- {
- unsigned qdRdm; /* treat return value as 0-65536 */
- long range, t;
-
- qdRdm = Random();
- range = max - min;
- t = (qdRdm * range) / 65536; /* now 0 <= t <= range */
- return( t+min );
- }
-
-
-
- void doContentClick (WindowPtr theWindow, EventRecord theEvent)
- {
- Point mouse;
- ControlHandle control;
- int checkBox;
- int part;
-
- SetPort(theWindow);
- mouse = theEvent.where;
- GlobalToLocal(&mouse);
- part = FindControl(mouse, theWindow, &control);
- if (( part > 0 ) && (control != nil)) {
- if (TrackControl(control, mouse, nil) != 0 )
- {
- checkBox = GetCtlValue(control);
- checkBox = 1 - checkBox;
- SetCtlValue(control, checkBox);
-
- switch (RangedRdm(1,5)) {
- case 1:
- CIB_SetTitleOrientation(control, atLeft);
- break;
-
- case 2:
- CIB_SetTitleOrientation(control, atRight);
- break;
-
- case 3:
- CIB_SetTitleOrientation(control, atTop);
- break;
-
- case 4:
- CIB_SetTitleOrientation(control, atBottom);
- break;
- }
- InvalRect(&(**control).contrlRect);
- };
- };
- }
-
-
- void DrawMyWindow(WindowPtr whichWindow, ControlHandle btn)
- {
- Rect textRect;
- Str255 theCopyright;
-
- FillRect(&whichWindow->portRect, gray);
-
- textRect = whichWindow->portRect;
- InsetRect(&textRect, 5, 5);
- textRect.bottom = textRect.top + 44;
- FillRect(&textRect, white);
-
- CIB_GetCopyright(btn, theCopyright);
- MoveTo(12,18);
- DrawString(theCopyright);
-
- MoveTo(12,30);
- DrawString("\pClick on the button to randomly change the title orientation.");
-
- MoveTo(12,42);
- DrawString("\pClick the close box or hit any key to quit.");
-
- UpdateControls(whichWindow, whichWindow->visRgn);
- }
-
- /*****
- * doSimpleWindow()
- *
- * Show a simple window with a single control
- *
- *****/
-
- void doSimpleWindow()
-
- {
- Boolean Done;
- WindowPtr theWindow;
- int windowPart;
- CWindowRecord wRecord;
- Rect limitRect;
- Rect rWindow;
-
- ControlHandle bPushButton;
- Rect itemBox;
-
- EventRecord theEvent;
- Point newWindowLoc;
- GrafPtr savePort;
- WindowPtr whichWindow;
-
- OSErr oe;
-
- bPushButton = nil;
- Done = FALSE;
- theWindow = nil;
- SetRect(&rWindow, 0, 0, 400, 150);
- OffsetRect(&rWindow, 50, 50);
- SetRect(&itemBox, 50, 50, 180, 120);
- limitRect = screenBits.bounds;
- theWindow = NewCWindow(nil, &rWindow, "\pCIconButton Demo", TRUE, documentProc, (WindowPtr)(-1), TRUE, 0);
-
- SetPort(theWindow);
- BackPat(gray);
- TextFont(geneva);
- TextSize(9);
-
- ShowWindow(theWindow);
-
- bPushButton = NewControl(theWindow, &itemBox, "\pTesting", FALSE, kSampleAlt, kSampleMain, kSampleShell, kButtonProc, 0);
- ShowControl(bPushButton);
-
- DrawMyWindow(theWindow,bPushButton);
-
- while (!Done) {
- if (WaitNextEvent(everyEvent, &theEvent, 0, nil))
-
- switch (theEvent.what) {
- case keyDown:
- Done = TRUE;
- break;
-
- case mouseDown:
- windowPart = FindWindow(theEvent.where, &theWindow);
- switch (windowPart) {
- case inDrag:
- DragWindow(theWindow, theEvent.where, &limitRect);
- newWindowLoc = topLeft(theWindow->portRect);
- LocalToGlobal(&newWindowLoc);
- MoveWindow(theWindow, newWindowLoc.h, newWindowLoc.v, TRUE);
- break;
-
- case inGoAway:
- Done = TrackGoAway(theWindow, theEvent.where);
- break;
-
- case inContent:
- doContentClick(theWindow, theEvent);
- break;
- }
- break;
-
- case updateEvt:
- GetPort(&savePort);
- whichWindow = (WindowPtr)(theEvent.message);
- BeginUpdate(whichWindow);
- DrawMyWindow(whichWindow, bPushButton);
- EndUpdate(whichWindow);
- SetPort(savePort);
- break;
-
- }
- };
-
- if ( theWindow != nil )
- DisposeWindow(theWindow);
- }
-
-
- main()
-
- {
-
- InitMacintosh();
-
- doSimpleWindow();
-
-
- }
-